package com.yxp.webtest.controller;

import com.yxp.webtest.bean.User;
import com.yxp.webtest.service.AddressService;
import com.yxp.webtest.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
//@Lazy 设置懒加载
public class UserController {

    public UserController() {
        System.out.println("init userController ---------------- ");
    }

    @Autowired
    UserService userService;

    @Autowired
    AddressService addressService;

    @RequestMapping("/queryUserList")
    @ResponseBody
    public List<User> queryUserList() {
        return userService.queryUserList();
    }

    /**
     * 返回的三种方式 https://www.cnblogs.com/gagazhao/p/6735803.html
     * @param model
     * @return
     */
    @RequestMapping("/queryUserListPage")
    public String queryUserListPage(Model model) {
        List<User> userList = userService.queryUserList();
        model.addAttribute("userList", userList);
        return "UserList";
    }
}
